<html><head><title>WaveFrontSensor.cpp</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="sourcestyles.css" />
</head><body link="blue" vlink="blue">
<h3>File: D:\project4\WaveFrontSensor\WaveFrontSensor.cpp</h3>
<SCRIPT>
defaultStatus = "File: D:\\project4\\WaveFrontSensor\\WaveFrontSensor.cpp";
top.document.title  = "WaveFrontSensor.cpp";
</SCRIPT>
<pre><span class="default"></span><a name="1"><font size=-1>1     </font></a><span class="default"></span><span class="preproc">#include </span><span class="string">&quot;WaveFrontSensor.h&quot;</span>
<a name="2"><font size=-1>2     </font></a><span class="string"></span>
<a name="3"><font size=-1>3     </font></a><span class="string"></span><span class="default">WaveFrontSensor::WaveFrontSensor(QWidget *parent)</span>
<a name="4"><font size=-1>4     </font></a><span class="default">    : QWidget(parent)</span>
<a name="5"><font size=-1>5     </font></a><span class="default">    , ui(</span><span class="keyword">new </span><span class="default">Ui::WaveFrontSensorClass())</span>
<a name="6"><font size=-1>6     </font></a><span class="default">{</span>
<a name="7"><font size=-1>7     </font></a><span class="default">    ui-&gt;setupUi(</span><span class="keyword">this</span><span class="default">);</span>
<a name="8"><font size=-1>8     </font></a><span class="default">    initDefaultDisplay();</span>
<a name="9"><font size=-1>9     </font></a><span class="default">    initInfoDialog();</span>
<a name="10"><font size=-1>10     </font></a><span class="default">    connect(select_data_tool_button_.data(), &amp;QToolButton::clicked, </span><span class="keyword">this</span><span class="default">, [&amp;]()-&gt;</span><span class="keyword">void </span><span class="default">{</span>
<a name="11"><font size=-1>11     </font></a><span class="default">        filename_ = QFileDialog::getOpenFileName(</span><span class="keyword">this</span><span class="default">, </span><span class="string">&quot; &quot;</span><span class="default">, </span><span class="string">&quot; &quot;</span><span class="default">, </span><span class="string">&quot;*.dat&quot;</span><span class="default">);</span>
<a name="12"><font size=-1>12     </font></a><span class="default">        </span><span class="keyword">if </span><span class="default">(filename_.isEmpty() || filename_.isNull()) {</span>
<a name="13"><font size=-1>13     </font></a><span class="default"></span>
<a name="14"><font size=-1>14     </font></a><span class="default">            QMessageBox::warning(</span><span class="keyword">this</span><span class="default">, </span><span class="string">&quot;警告&quot;</span><span class="default">, u8</span><span class="string">&quot;没有获得选择的数据，请重新选择数据&quot;</span><span class="default">);</span>
<a name="15"><font size=-1>15     </font></a><span class="default">            </span><span class="keyword">return</span><span class="default">;</span>
<a name="16"><font size=-1>16     </font></a><span class="default"></span>
<a name="17"><font size=-1>17     </font></a><span class="default">        }</span>
<a name="18"><font size=-1>18     </font></a><span class="default"></span>
<a name="19"><font size=-1>19     </font></a><span class="default">        </span><span class="keyword">try </span><span class="default">{</span>
<a name="20"><font size=-1>20     </font></a><span class="default"></span>
<a name="21"><font size=-1>21     </font></a><span class="default">            Configuration configuration;</span>
<a name="22"><font size=-1>22     </font></a><span class="default">            QVector2D_ waveFrontImageData = readWaveFrontSensorImageDat(filename_, configuration[</span><span class="string">&quot;nu_detector&quot;</span><span class="default">], configuration[</span><span class="string">&quot;nv_detector&quot;</span><span class="default">], configuration[</span><span class="string">&quot;upsampling&quot;</span><span class="default">]);</span>
<a name="23"><font size=-1>23     </font></a><span class="default">            QVector&lt;QVector&lt;quint16&gt;&gt; qt_hartmanngram_png = addNoNoise(waveFrontImageData);</span>
<a name="24"><font size=-1>24     </font></a><span class="default">            QString png_filename = </span><span class="string">&quot;./data_example_21/ex21_res_int_pr_se.dat.png&quot;</span><span class="default">;</span>
<a name="25"><font size=-1>25     </font></a><span class="default">            cv::Mat hartmanngramm_png(qt_hartmanngram_png.size(), qt_hartmanngram_png[</span><span class="number">0</span><span class="default">].size(),CV_16U);</span>
<a name="26"><font size=-1>26     </font></a><span class="default">            HIOlAB_CXX_14::array2D_Convert_CV_Mat&lt;quint16,</span><span class="keyword">unsigned short</span><span class="default">&gt;(qt_hartmanngram_png,hartmanngramm_png);</span>
<a name="27"><font size=-1>27     </font></a><span class="default">            writreGaryscalePNG(hartmanngramm_png);</span>
<a name="28"><font size=-1>28     </font></a><span class="default">            cv::Mat starting_pixel=(cv::Mat_&lt;</span><span class="keyword">int</span><span class="default">&gt;(</span><span class="number">1</span><span class="default">,</span><span class="number">2</span><span class="default">)&lt;&lt; </span><span class="keyword">static_cast</span><span class="default">&lt;</span><span class="keyword">int</span><span class="default">&gt;(configuration[</span><span class="string">&quot;nu_detector&quot;</span><span class="default">] / </span><span class="number">2</span><span class="default">),</span><span class="keyword">static_cast</span><span class="default">&lt;</span><span class="keyword">int</span><span class="default">&gt;(configuration[</span><span class="string">&quot;nv_detector&quot;</span><span class="default">]));</span>
<a name="29"><font size=-1>29     </font></a><span class="default">            processHartmanngram(configuration, hartmanngramm_png, starting_pixel,HIOlAB_CXX_14::ThresholdMode::OTSU);</span>
<a name="30"><font size=-1>30     </font></a><span class="default">        }</span>
<a name="31"><font size=-1>31     </font></a><span class="default">        </span><span class="keyword">catch </span><span class="default">(</span><span class="keyword">const </span><span class="default">std::exception&amp; RUN_TIME_EXCEPTION) {</span>
<a name="32"><font size=-1>32     </font></a><span class="default"></span>
<a name="33"><font size=-1>33     </font></a><span class="default">            HIOlAB_CXX_14::ExceptionInfoPrint(RUN_TIME_EXCEPTION.what());</span>
<a name="34"><font size=-1>34     </font></a><span class="default">        }</span>
<a name="35"><font size=-1>35     </font></a><span class="default"></span>
<a name="36"><font size=-1>36     </font></a><span class="default">        });</span>
<a name="37"><font size=-1>37     </font></a><span class="default">}</span>
<a name="38"><font size=-1>38     </font></a><span class="default"></span>
<a name="39"><font size=-1>39     </font></a><span class="default">WaveFrontSensor::~WaveFrontSensor()</span>
<a name="40"><font size=-1>40     </font></a><span class="default">{</span>
<a name="41"><font size=-1>41     </font></a><span class="default">    free();</span>
<a name="42"><font size=-1>42     </font></a><span class="default">    </span><span class="keyword">delete </span><span class="default">ui;</span>
<a name="43"><font size=-1>43     </font></a><span class="default"></span>
<a name="44"><font size=-1>44     </font></a><span class="default">}</span>
<a name="45"><font size=-1>45     </font></a><span class="default"></span>
<a name="46"><font size=-1>46     </font></a><span class="default"></span>
<a name="47"><font size=-1>47     </font></a><span class="default"></span><span class="keyword">void </span><span class="default">WaveFrontSensor::initDefaultDisplay() {</span>
<a name="48"><font size=-1>48     </font></a><span class="default"></span>
<a name="49"><font size=-1>49     </font></a><span class="default">    grid_layout_ = </span><span class="keyword">new </span><span class="default">QGridLayout(</span><span class="keyword">this</span><span class="default">);</span>
<a name="50"><font size=-1>50     </font></a><span class="default">    select_data_tool_button_ = QSharedPointer&lt;QToolButton&gt;(</span><span class="keyword">new </span><span class="default">QToolButton());</span>
<a name="51"><font size=-1>51     </font></a><span class="default">    select_data_tool_button_-&gt;setText(u8</span><span class="string">&quot;Start&quot;</span><span class="default">);</span>
<a name="52"><font size=-1>52     </font></a><span class="default">    grid_layout_-&gt;addWidget(select_data_tool_button_.data(), </span><span class="number">0</span><span class="default">, </span><span class="number">0</span><span class="default">);</span>
<a name="53"><font size=-1>53     </font></a><span class="default"></span>
<a name="54"><font size=-1>54     </font></a><span class="default"></span>
<a name="55"><font size=-1>55     </font></a><span class="default">    graphic_view = </span><span class="keyword">new </span><span class="default">QGraphicsView();</span>
<a name="56"><font size=-1>56     </font></a><span class="default">    graphio_scene = </span><span class="keyword">new </span><span class="default">QGraphicsScene();</span>
<a name="57"><font size=-1>57     </font></a><span class="default">    graphic_view-&gt;setScene(graphio_scene);</span>
<a name="58"><font size=-1>58     </font></a><span class="default">}</span>
<a name="59"><font size=-1>59     </font></a><span class="default"></span>
<a name="60"><font size=-1>60     </font></a><span class="default"></span>
<a name="61"><font size=-1>61     </font></a><span class="default"></span>
<a name="62"><font size=-1>62     </font></a><span class="default"></span><span class="comment">/**</span>
<a name="63"><font size=-1>63     </font></a><span class="comment"> * 默认的值</span>
<a name="64"><font size=-1>64     </font></a><span class="comment"> * \param filename   &quot;data_exmaple_21//ex21_res_int_pr_se.dat&quot;</span>
<a name="65"><font size=-1>65     </font></a><span class="comment"> * \param nu_detector 512</span>
<a name="66"><font size=-1>66     </font></a><span class="comment"> * \param nv_detector 512</span>
<a name="67"><font size=-1>67     </font></a><span class="comment"> * \param upsampleing  2</span>
<a name="68"><font size=-1>68     </font></a><span class="comment"> * \return  Array 2D</span>
<a name="69"><font size=-1>69     </font></a><span class="comment"> */</span>
<a name="70"><font size=-1>70     </font></a><span class="comment"></span><span class="keyword">void </span><span class="default">WaveFrontSensor::readDataFromDisk(QString filename, QVector&lt;</span><span class="keyword">float</span><span class="default">&gt;&amp; intensity) {</span>
<a name="71"><font size=-1>71     </font></a><span class="default"></span>
<a name="72"><font size=-1>72     </font></a><span class="default">    QFile file(filename);</span>
<a name="73"><font size=-1>73     </font></a><span class="default">    </span><span class="keyword">if </span><span class="default">(file.open(QIODevice::ReadOnly | QIODevice::Text)) {</span>
<a name="74"><font size=-1>74     </font></a><span class="default"></span>
<a name="75"><font size=-1>75     </font></a><span class="default">        QTextStream outputStream(&amp;file);</span>
<a name="76"><font size=-1>76     </font></a><span class="default">        </span><span class="keyword">int </span><span class="default">lineToSkip = </span><span class="number">10</span><span class="default">;</span>
<a name="77"><font size=-1>77     </font></a><span class="default">        </span><span class="keyword">for </span><span class="default">(</span><span class="keyword">int </span><span class="default">i = </span><span class="number">0</span><span class="default">; i &lt; lineToSkip; i++) {</span>
<a name="78"><font size=-1>78     </font></a><span class="default"></span>
<a name="79"><font size=-1>79     </font></a><span class="default">            outputStream.readLine();</span>
<a name="80"><font size=-1>80     </font></a><span class="default">        }</span>
<a name="81"><font size=-1>81     </font></a><span class="default"></span>
<a name="82"><font size=-1>82     </font></a><span class="default">        </span><span class="keyword">while </span><span class="default">(!outputStream.atEnd()) {</span>
<a name="83"><font size=-1>83     </font></a><span class="default"></span>
<a name="84"><font size=-1>84     </font></a><span class="default">            QString line = outputStream.readLine();</span>
<a name="85"><font size=-1>85     </font></a><span class="default"></span>
<a name="86"><font size=-1>86     </font></a><span class="default">            intensity.append(line.toFloat());</span>
<a name="87"><font size=-1>87     </font></a><span class="default">        }</span>
<a name="88"><font size=-1>88     </font></a><span class="default">        file.close();</span>
<a name="89"><font size=-1>89     </font></a><span class="default">    }</span>
<a name="90"><font size=-1>90     </font></a><span class="default">    </span><span class="keyword">else </span><span class="default">{</span>
<a name="91"><font size=-1>91     </font></a><span class="default"></span>
<a name="92"><font size=-1>92     </font></a><span class="default">        </span><span class="keyword">throw </span><span class="default">FileOpenException();</span>
<a name="93"><font size=-1>93     </font></a><span class="default">    }</span>
<a name="94"><font size=-1>94     </font></a><span class="default">}</span>
<a name="95"><font size=-1>95     </font></a><span class="default"></span>
<a name="96"><font size=-1>96     </font></a><span class="default"></span>
<a name="97"><font size=-1>97     </font></a><span class="default"></span>
<a name="98"><font size=-1>98     </font></a><span class="default"></span>
<a name="99"><font size=-1>99     </font></a><span class="default"></span><span class="keyword">void </span><span class="default">WaveFrontSensor::initInfoDialog() {</span>
<a name="100"><font size=-1>100     </font></a><span class="default">    </span>
<a name="101"><font size=-1>101     </font></a><span class="default">    dialog = </span><span class="keyword">new </span><span class="default">QDialog();</span>
<a name="102"><font size=-1>102     </font></a><span class="default">    dialog-&gt;setWindowTitle(u8</span><span class="string">&quot;加载信息窗口&quot;</span><span class="default">);</span>
<a name="103"><font size=-1>103     </font></a><span class="default">    dialog-&gt;setFixedSize(</span><span class="number">400</span><span class="default">, </span><span class="number">500</span><span class="default">);</span>
<a name="104"><font size=-1>104     </font></a><span class="default">    infoText = </span><span class="keyword">new </span><span class="default">QPlainTextEdit(dialog);</span>
<a name="105"><font size=-1>105     </font></a><span class="default">    infoText-&gt;setReadOnly(</span><span class="keyword">true</span><span class="default">);</span>
<a name="106"><font size=-1>106     </font></a><span class="default">    infoText-&gt;setFixedSize(dialog-&gt;size());</span>
<a name="107"><font size=-1>107     </font></a><span class="default">}</span>
<a name="108"><font size=-1>108     </font></a><span class="default"></span>
<a name="109"><font size=-1>109     </font></a><span class="default"></span><span class="keyword">void </span><span class="default">WaveFrontSensor::CAT_DATA_INFO(</span><span class="keyword">const </span><span class="default">QVector4D_&amp; array_4d , </span><span class="keyword">const </span><span class="default">QVector3D_&amp; array_3d) {</span>
<a name="110"><font size=-1>110     </font></a><span class="default"></span>
<a name="111"><font size=-1>111     </font></a><span class="default"></span>
<a name="112"><font size=-1>112     </font></a><span class="default">    infoText-&gt;appendPlainText(u8</span><span class="string">&quot;&gt;&gt;&gt;程序初始化......... &quot;</span><span class="default">);</span>
<a name="113"><font size=-1>113     </font></a><span class="default">    infoText-&gt;appendPlainText(u8</span><span class="string">&quot;&gt;&gt;&gt;程序初始化成功 &quot;</span><span class="default">);</span>
<a name="114"><font size=-1>114     </font></a><span class="default">    infoText-&gt;appendPlainText(u8</span><span class="string">&quot;&gt;&gt;&gt;加载数据成功 &quot;</span><span class="default">);</span>
<a name="115"><font size=-1>115     </font></a><span class="default">    infoText-&gt;appendPlainText(</span><span class="string">&quot;\n&quot;</span><span class="default">);</span>
<a name="116"><font size=-1>116     </font></a><span class="default">    infoText-&gt;appendPlainText(u8</span><span class="string">&quot;加载的数据如下 &quot;</span><span class="default">);</span>
<a name="117"><font size=-1>117     </font></a><span class="default">    infoText-&gt;appendPlainText(QString::number(array_4d.size()));</span>
<a name="118"><font size=-1>118     </font></a><span class="default">    infoText-&gt;appendPlainText(QString::number(array_4d[</span><span class="number">0</span><span class="default">].size()));</span>
<a name="119"><font size=-1>119     </font></a><span class="default">    infoText-&gt;appendPlainText(QString::number(array_4d[</span><span class="number">0</span><span class="default">][</span><span class="number">0</span><span class="default">].size()));</span>
<a name="120"><font size=-1>120     </font></a><span class="default">    infoText-&gt;appendPlainText(QString::number(array_4d[</span><span class="number">0</span><span class="default">][</span><span class="number">0</span><span class="default">][</span><span class="number">0</span><span class="default">].size()));</span>
<a name="121"><font size=-1>121     </font></a><span class="default">    infoText-&gt;appendPlainText(u8</span><span class="string">&quot;最后两个元素 &quot;</span><span class="default">);</span>
<a name="122"><font size=-1>122     </font></a><span class="default">    infoText-&gt;appendPlainText(QString::number(array_4d[</span><span class="number">511</span><span class="default">][</span><span class="number">1</span><span class="default">][</span><span class="number">511</span><span class="default">][</span><span class="number">0</span><span class="default">]));</span>
<a name="123"><font size=-1>123     </font></a><span class="default">    infoText-&gt;appendPlainText(QString::number(array_4d[</span><span class="number">511</span><span class="default">][</span><span class="number">1</span><span class="default">][</span><span class="number">511</span><span class="default">][</span><span class="number">1</span><span class="default">]));</span>
<a name="124"><font size=-1>124     </font></a><span class="default"></span>
<a name="125"><font size=-1>125     </font></a><span class="default">    infoText-&gt;appendPlainText(u8</span><span class="string">&quot;沿着坐标轴3的均值矩阵shape为 &quot;</span><span class="default">);</span>
<a name="126"><font size=-1>126     </font></a><span class="default">    infoText-&gt;appendPlainText(QString::number(array_3d.size()));</span>
<a name="127"><font size=-1>127     </font></a><span class="default">    infoText-&gt;appendPlainText(QString::number(array_3d[</span><span class="number">0</span><span class="default">].size()));</span>
<a name="128"><font size=-1>128     </font></a><span class="default">    infoText-&gt;appendPlainText(QString::number(array_3d[</span><span class="number">0</span><span class="default">][</span><span class="number">0</span><span class="default">].size()));</span>
<a name="129"><font size=-1>129     </font></a><span class="default">    infoText-&gt;appendPlainText(u8</span><span class="string">&quot;沿着坐标轴3的均值矩阵前的两个值  &quot;</span><span class="default">);</span>
<a name="130"><font size=-1>130     </font></a><span class="default"></span>
<a name="131"><font size=-1>131     </font></a><span class="default">    infoText-&gt;appendPlainText(QString::number(array_3d[</span><span class="number">0</span><span class="default">][</span><span class="number">0</span><span class="default">][</span><span class="number">0</span><span class="default">]));</span>
<a name="132"><font size=-1>132     </font></a><span class="default">    infoText-&gt;appendPlainText(QString::number(array_3d[</span><span class="number">0</span><span class="default">][</span><span class="number">0</span><span class="default">][</span><span class="number">1</span><span class="default">]));</span>
<a name="133"><font size=-1>133     </font></a><span class="default">    infoText-&gt;appendPlainText(u8</span><span class="string">&quot;沿着坐标轴3的均值矩阵最后的两个值  &quot;</span><span class="default">);</span>
<a name="134"><font size=-1>134     </font></a><span class="default"></span>
<a name="135"><font size=-1>135     </font></a><span class="default">    infoText-&gt;appendPlainText(QString::number(array_3d[</span><span class="number">511</span><span class="default">][</span><span class="number">1</span><span class="default">][</span><span class="number">510</span><span class="default">]));</span>
<a name="136"><font size=-1>136     </font></a><span class="default">    infoText-&gt;appendPlainText(QString::number(array_3d[</span><span class="number">511</span><span class="default">][</span><span class="number">1</span><span class="default">][</span><span class="number">511</span><span class="default">]));</span>
<a name="137"><font size=-1>137     </font></a><span class="default">    dialog-&gt;show();</span>
<a name="138"><font size=-1>138     </font></a><span class="default">}</span>
<a name="139"><font size=-1>139     </font></a><span class="default"></span>
<a name="140"><font size=-1>140     </font></a><span class="default"></span>
<a name="141"><font size=-1>141     </font></a><span class="default"></span>
<a name="142"><font size=-1>142     </font></a><span class="default"></span><span class="comment">/**</span>
<a name="143"><font size=-1>143     </font></a><span class="comment"> * .</span>
<a name="144"><font size=-1>144     </font></a><span class="comment"> * \param filename      采集到的数据</span>
<a name="145"><font size=-1>145     </font></a><span class="comment"> * \param nu_detector   水平方向的检测</span>
<a name="146"><font size=-1>146     </font></a><span class="comment"> * \param nv_detector   竖直方向上的检测</span>
<a name="147"><font size=-1>147     </font></a><span class="comment"> * \param upsampleing   采样大小</span>
<a name="148"><font size=-1>148     </font></a><span class="comment"> * 存在问题 如果数据类型维单精度float 我只想开辟一块4维空间(512,2,512,2)8MB 一块3维空间(512,2,512)4MB 一块2维空间(1024,1024)8MB 1块一维空间1024*1024  8MB，total=28MB 但是单线程读取磁盘是否太慢了经过实验大约需要3s</span>
<a name="149"><font size=-1>149     </font></a><span class="comment"> */</span>
<a name="150"><font size=-1>150     </font></a><span class="comment"></span><span class="default">QVector&lt;QVector&lt;</span><span class="keyword">float</span><span class="default">&gt;&gt; WaveFrontSensor::readWaveFrontSensorImageDat(QString filename, </span><span class="keyword">float </span><span class="default">nu_detector, </span><span class="keyword">float </span><span class="default">nv_detector, </span><span class="keyword">int </span><span class="default">upsampleing) {</span>
<a name="151"><font size=-1>151     </font></a><span class="default">    </span>
<a name="152"><font size=-1>152     </font></a><span class="default">    QVector&lt;</span><span class="keyword">float</span><span class="default">&gt; intensity;</span>
<a name="153"><font size=-1>153     </font></a><span class="default">    QSize size(</span><span class="keyword">static_cast</span><span class="default">&lt;</span><span class="keyword">int</span><span class="default">&gt;(upsampleing * nv_detector), </span><span class="keyword">static_cast</span><span class="default">&lt;</span><span class="keyword">int</span><span class="default">&gt;(upsampleing * nu_detector));</span>
<a name="154"><font size=-1>154     </font></a><span class="default"></span>
<a name="155"><font size=-1>155     </font></a><span class="default">    </span><span class="keyword">try </span><span class="default">{</span>
<a name="156"><font size=-1>156     </font></a><span class="default"></span>
<a name="157"><font size=-1>157     </font></a><span class="default">        TimeConsuming timer;</span>
<a name="158"><font size=-1>158     </font></a><span class="default">        std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();</span>
<a name="159"><font size=-1>159     </font></a><span class="default">        timer.setStartTime(start);</span>
<a name="160"><font size=-1>160     </font></a><span class="default">        readDataFromDisk(filename, intensity);</span>
<a name="161"><font size=-1>161     </font></a><span class="default">        std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();</span>
<a name="162"><font size=-1>162     </font></a><span class="default">        timer.setEndTime(end);</span>
<a name="163"><font size=-1>163     </font></a><span class="default">        std::chrono::duration&lt;</span><span class="keyword">double</span><span class="default">&gt; duration=timer.calculateDuration();</span>
<a name="164"><font size=-1>164     </font></a><span class="default">        qDebug() &lt;&lt;u8</span><span class="string">&quot;从磁盘读取文件耗时 &quot; </span><span class="default">&lt;&lt; duration.count() / (</span><span class="number">1000000</span><span class="default">) &lt;&lt; </span><span class="string">&quot; s&quot;</span><span class="default">;</span>
<a name="165"><font size=-1>165     </font></a><span class="default">    }</span>
<a name="166"><font size=-1>166     </font></a><span class="default">    </span><span class="keyword">catch </span><span class="default">(</span><span class="keyword">const </span><span class="default">std::exception&amp; fileOpenException) {</span>
<a name="167"><font size=-1>167     </font></a><span class="default"></span>
<a name="168"><font size=-1>168     </font></a><span class="default">        HIOlAB_CXX_14::ExceptionInfoPrint(fileOpenException.what());</span>
<a name="169"><font size=-1>169     </font></a><span class="default">    }</span>
<a name="170"><font size=-1>170     </font></a><span class="default"></span>
<a name="171"><font size=-1>171     </font></a><span class="default"></span>
<a name="172"><font size=-1>172     </font></a><span class="default">    QVector2D_ Intensity2D;</span>
<a name="173"><font size=-1>173     </font></a><span class="default">    Intensity2D.resize(size.height());</span>
<a name="174"><font size=-1>174     </font></a><span class="default"></span>
<a name="175"><font size=-1>175     </font></a><span class="default">    </span><span class="keyword">for </span><span class="default">(</span><span class="keyword">int </span><span class="default">i = </span><span class="number">0</span><span class="default">; i &lt; Intensity2D.size(); i++) {</span>
<a name="176"><font size=-1>176     </font></a><span class="default"></span>
<a name="177"><font size=-1>177     </font></a><span class="default">        Intensity2D[i].resize(size.width());</span>
<a name="178"><font size=-1>178     </font></a><span class="default">    }</span>
<a name="179"><font size=-1>179     </font></a><span class="default"></span>
<a name="180"><font size=-1>180     </font></a><span class="default">    HIOlAB_CXX_14::reshape(intensity, Intensity2D, size.height(), size.width());</span>
<a name="181"><font size=-1>181     </font></a><span class="default">    HIOlAB_CXX_14::flipud(Intensity2D);</span>
<a name="182"><font size=-1>182     </font></a><span class="default"></span>
<a name="183"><font size=-1>183     </font></a><span class="default">    </span>
<a name="184"><font size=-1>184     </font></a><span class="default">    </span><span class="keyword">int </span><span class="default">dim[] = { </span><span class="keyword">static_cast</span><span class="default">&lt;</span><span class="keyword">int</span><span class="default">&gt;(nv_detector),upsampleing,</span><span class="keyword">static_cast</span><span class="default">&lt;</span><span class="keyword">int</span><span class="default">&gt;(nu_detector),upsampleing };</span>
<a name="185"><font size=-1>185     </font></a><span class="default"></span>
<a name="186"><font size=-1>186     </font></a><span class="default">    QVector4D_ Array4D(dim[</span><span class="number">0</span><span class="default">], QVector&lt;QVector&lt;QVector&lt;</span><span class="keyword">float</span><span class="default">&gt;&gt;&gt;(dim[</span><span class="number">1</span><span class="default">], QVector&lt;QVector&lt;</span><span class="keyword">float</span><span class="default">&gt;&gt;(dim[</span><span class="number">2</span><span class="default">], QVector&lt;</span><span class="keyword">float</span><span class="default">&gt;(dim[</span><span class="number">3</span><span class="default">], </span><span class="number">0</span><span class="default">))));</span>
<a name="187"><font size=-1>187     </font></a><span class="default"></span>
<a name="188"><font size=-1>188     </font></a><span class="default">    </span><span class="keyword">try </span><span class="default">{</span>
<a name="189"><font size=-1>189     </font></a><span class="default"></span>
<a name="190"><font size=-1>190     </font></a><span class="default">        HIOlAB_CXX_14::convertArray2D_TO_Array_4D(Intensity2D, dim[</span><span class="number">0</span><span class="default">], dim[</span><span class="number">1</span><span class="default">], dim[</span><span class="number">2</span><span class="default">], dim[</span><span class="number">3</span><span class="default">], Array4D);</span>
<a name="191"><font size=-1>191     </font></a><span class="default">    }</span>
<a name="192"><font size=-1>192     </font></a><span class="default">    </span><span class="keyword">catch </span><span class="default">(</span><span class="keyword">const </span><span class="default">std::exception&amp; dimConvertException) {</span>
<a name="193"><font size=-1>193     </font></a><span class="default"></span>
<a name="194"><font size=-1>194     </font></a><span class="default">        HIOlAB_CXX_14::ExceptionInfoPrint(dimConvertException.what());</span>
<a name="195"><font size=-1>195     </font></a><span class="default">    }</span>
<a name="196"><font size=-1>196     </font></a><span class="default"></span>
<a name="197"><font size=-1>197     </font></a><span class="default">    QVector3D_  Array3D(dim[</span><span class="number">0</span><span class="default">],QVector&lt;QVector&lt;</span><span class="keyword">float</span><span class="default">&gt;&gt;(dim[</span><span class="number">1</span><span class="default">],QVector&lt;</span><span class="keyword">float</span><span class="default">&gt;(dim[</span><span class="number">2</span><span class="default">],</span><span class="number">0</span><span class="default">)));   </span>
<a name="198"><font size=-1>198     </font></a><span class="default">    HIOlAB_CXX_14::Mean_Axis_3(Array4D, dim, Array3D);</span>
<a name="199"><font size=-1>199     </font></a><span class="default">    QVector2D_ waveFrontImage(dim[</span><span class="number">0</span><span class="default">], QVector&lt;</span><span class="keyword">float</span><span class="default">&gt;(dim[</span><span class="number">2</span><span class="default">], </span><span class="number">0</span><span class="default">));</span>
<a name="200"><font size=-1>200     </font></a><span class="default">    HIOlAB_CXX_14::Mean_Axis_1(Array3D,dim[</span><span class="number">0</span><span class="default">],dim[</span><span class="number">1</span><span class="default">],dim[</span><span class="number">2</span><span class="default">], waveFrontImage);</span>
<a name="201"><font size=-1>201     </font></a><span class="default">    CAT_DATA_INFO(Array4D, Array3D);</span>
<a name="202"><font size=-1>202     </font></a><span class="default"></span>
<a name="203"><font size=-1>203     </font></a><span class="default">    infoText-&gt;appendPlainText(QString(u8</span><span class="string">&quot;二维均值矩阵的最前面两个元素 &quot;</span><span class="default">) + QString::number(waveFrontImage[</span><span class="number">0</span><span class="default">][</span><span class="number">0</span><span class="default">]) + QString::number(waveFrontImage[</span><span class="number">0</span><span class="default">][</span><span class="number">1</span><span class="default">]));</span>
<a name="204"><font size=-1>204     </font></a><span class="default">    infoText-&gt;appendPlainText(QString(u8</span><span class="string">&quot;二维均值矩阵的最后面两个元素 &quot;</span><span class="default">) + QString::number(waveFrontImage[</span><span class="number">511</span><span class="default">][</span><span class="number">510</span><span class="default">]) + QString::number(waveFrontImage[</span><span class="number">511</span><span class="default">][</span><span class="number">511</span><span class="default">]));</span>
<a name="205"><font size=-1>205     </font></a><span class="default"></span>
<a name="206"><font size=-1>206     </font></a><span class="default">    </span><span class="keyword">return </span><span class="default">waveFrontImage;</span>
<a name="207"><font size=-1>207     </font></a><span class="default">}</span>
<a name="208"><font size=-1>208     </font></a><span class="default"></span>
<a name="209"><font size=-1>209     </font></a><span class="default"></span>
<a name="210"><font size=-1>210     </font></a><span class="default"></span>
<a name="211"><font size=-1>211     </font></a><span class="default"></span>
<a name="212"><font size=-1>212     </font></a><span class="default">QVector&lt;QVector&lt;quint16&gt;&gt; WaveFrontSensor::addNoNoise(QVector2D_&amp; intensity_map) {</span>
<a name="213"><font size=-1>213     </font></a><span class="default">    QVector&lt;QVector&lt;quint16&gt;&gt; detector_image;</span>
<a name="214"><font size=-1>214     </font></a><span class="default">    </span><span class="keyword">char </span><span class="default">pixel_depth = </span><span class="number">14</span><span class="default">;</span>
<a name="215"><font size=-1>215     </font></a><span class="default"></span>
<a name="216"><font size=-1>216     </font></a><span class="default">    TimeConsuming timer;</span>
<a name="217"><font size=-1>217     </font></a><span class="default">    std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();</span>
<a name="218"><font size=-1>218     </font></a><span class="default"></span>
<a name="219"><font size=-1>219     </font></a><span class="default">    </span><span class="keyword">auto </span><span class="default">min_value = HIOlAB_CXX_14::minValue(intensity_map);</span>
<a name="220"><font size=-1>220     </font></a><span class="default">    </span><span class="keyword">auto </span><span class="default">max_vaue  = HIOlAB_CXX_14::maxValue(intensity_map);</span>
<a name="221"><font size=-1>221     </font></a><span class="default">    HIOlAB_CXX_14::</span><span class="keyword">operator</span><span class="default">-(intensity_map, min_value); </span>
<a name="222"><font size=-1>222     </font></a><span class="default">    HIOlAB_CXX_14::</span><span class="keyword">operator</span><span class="default">/(intensity_map, max_vaue - min_value);</span>
<a name="223"><font size=-1>223     </font></a><span class="default">    HIOlAB_CXX_14::</span><span class="keyword">operator</span><span class="default">*(intensity_map, std::pow(</span><span class="number">2</span><span class="default">, pixel_depth) - </span><span class="number">1</span><span class="default">);</span>
<a name="224"><font size=-1>224     </font></a><span class="default">    HIOlAB_CXX_14::floor(intensity_map);</span>
<a name="225"><font size=-1>225     </font></a><span class="default">    HIOlAB_CXX_14::thresholdProcessing(intensity_map, std::pow(</span><span class="number">2</span><span class="default">, pixel_depth) - </span><span class="number">1</span><span class="default">);</span>
<a name="226"><font size=-1>226     </font></a><span class="default">    HIOlAB_CXX_14::astype(intensity_map, detector_image);</span>
<a name="227"><font size=-1>227     </font></a><span class="default"></span>
<a name="228"><font size=-1>228     </font></a><span class="default">    std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();</span>
<a name="229"><font size=-1>229     </font></a><span class="default">    std::chrono::duration&lt;</span><span class="keyword">double</span><span class="default">&gt; duration = std::chrono::duration_cast&lt;std::chrono::duration&lt;</span><span class="keyword">double</span><span class="default">&gt;&gt;(end-start);</span>
<a name="230"><font size=-1>230     </font></a><span class="default">    intensity_map.clear();</span>
<a name="231"><font size=-1>231     </font></a><span class="default">    </span><span class="keyword">return  </span><span class="default">detector_image;</span>
<a name="232"><font size=-1>232     </font></a><span class="default">}</span>
<a name="233"><font size=-1>233     </font></a><span class="default"></span>
<a name="234"><font size=-1>234     </font></a><span class="default"></span>
<a name="235"><font size=-1>235     </font></a><span class="default"></span><span class="keyword">void </span><span class="default">WaveFrontSensor::writreGaryscalePNG(</span><span class="keyword">const </span><span class="default">cv::Mat&amp; hartmanngram_png) {</span>
<a name="236"><font size=-1>236     </font></a><span class="default">    </span>
<a name="237"><font size=-1>237     </font></a><span class="default">    QString png_filename = </span><span class="string">&quot;./data_example_21/ex21_res_int_pr_se.dat.png&quot;</span><span class="default">;</span>
<a name="238"><font size=-1>238     </font></a><span class="default">    cv::imwrite(png_filename.toStdString(), hartmanngram_png);</span>
<a name="239"><font size=-1>239     </font></a><span class="default">    qDebug() &lt;&lt; </span><span class="string">&quot;write success &quot; </span><span class="default">&lt;&lt; </span><span class="string">&quot;\n&quot;</span><span class="default">;</span>
<a name="240"><font size=-1>240     </font></a><span class="default">    </span>
<a name="241"><font size=-1>241     </font></a><span class="default">}</span>
<a name="242"><font size=-1>242     </font></a><span class="default"></span>
<a name="243"><font size=-1>243     </font></a><span class="default"></span>
<a name="244"><font size=-1>244     </font></a><span class="default"></span>
<a name="245"><font size=-1>245     </font></a><span class="default"></span><span class="keyword">void </span><span class="default">WaveFrontSensor::setConfHartmanngramFilename(Configuration&amp; configuration) {</span>
<a name="246"><font size=-1>246     </font></a><span class="default"></span>
<a name="247"><font size=-1>247     </font></a><span class="default">}</span>
<a name="248"><font size=-1>248     </font></a><span class="default"></span>
<a name="249"><font size=-1>249     </font></a><span class="default"></span>
<a name="250"><font size=-1>250     </font></a><span class="default"></span><span class="keyword">void </span><span class="default">WaveFrontSensor::analyzeHartmanngram(  cv::Mat&amp; hartmanngram, </span><span class="keyword">float </span><span class="default">dist_mask_to_detector, </span><span class="keyword">float </span><span class="default">pixel_size, </span><span class="keyword">float </span><span class="default">grid_period, </span>
<a name="251"><font size=-1>251     </font></a><span class="default">                                             HIOlAB_CXX_14::ThresholdMode thresholding_mode,</span>
<a name="252"><font size=-1>252     </font></a><span class="default">                                             </span><span class="keyword">unsigned char </span><span class="default">img_int_thr, </span><span class="keyword">int </span><span class="default">block_size, </span><span class="keyword">int </span><span class="default">area_thr, </span><span class="keyword">int </span><span class="default">min_fringle_number, </span>
<a name="253"><font size=-1>253     </font></a><span class="default">                                             cv::Mat starting_pixel, </span><span class="keyword">float </span><span class="default">ration_thr,</span>
<a name="254"><font size=-1>254     </font></a><span class="default">                                             </span><span class="keyword">float </span><span class="default">centroid_power, </span>
<a name="255"><font size=-1>255     </font></a><span class="default">                                             </span><span class="keyword">int   </span><span class="default">min_order_u, </span><span class="keyword">int </span><span class="default">max_order_u, </span>
<a name="256"><font size=-1>256     </font></a><span class="default">                                             </span><span class="keyword">int   </span><span class="default">min_order_v, </span><span class="keyword">int </span><span class="default">max_order_v, </span>
<a name="257"><font size=-1>257     </font></a><span class="default">                                             </span><span class="keyword">int   </span><span class="default">edge_exclusion,</span>
<a name="258"><font size=-1>258     </font></a><span class="default">                                             </span><span class="keyword">bool  </span><span class="default">is_show)</span>
<a name="259"><font size=-1>259     </font></a><span class="default">{</span>
<a name="260"><font size=-1>260     </font></a><span class="default">    infoText-&gt;appendPlainText(</span><span class="string">&quot;\n&quot;</span><span class="default">);</span>
<a name="261"><font size=-1>261     </font></a><span class="default">    infoText-&gt;appendPlainText(u8</span><span class="string">&quot;***************************&quot;</span><span class="default">);</span>
<a name="262"><font size=-1>262     </font></a><span class="default">    infoText-&gt;appendPlainText(u8</span><span class="string">&quot;开始计算 hartmanngram的坡度 &quot;</span><span class="default">);</span>
<a name="263"><font size=-1>263     </font></a><span class="default"></span>
<a name="264"><font size=-1>264     </font></a><span class="default">    cv::Mat x2d_image_um(hartmanngram.size().height, hartmanngram.size().width,CV_16U);</span>
<a name="265"><font size=-1>265     </font></a><span class="default">    cv::Mat y2d_image_um(hartmanngram.size().height, hartmanngram.size().width,CV_16U);</span>
<a name="266"><font size=-1>266     </font></a><span class="default"></span>
<a name="267"><font size=-1>267     </font></a><span class="default">    HIOlAB_CXX_14::meshgridX&lt;</span><span class="keyword">int</span><span class="default">,</span><span class="keyword">unsigned short</span><span class="default">&gt;(</span><span class="number">0</span><span class="default">,hartmanngram.size().width,x2d_image_um);</span>
<a name="268"><font size=-1>268     </font></a><span class="default">    HIOlAB_CXX_14::meshgridY&lt;</span><span class="keyword">int</span><span class="default">,</span><span class="keyword">unsigned short</span><span class="default">&gt;(</span><span class="number">0</span><span class="default">,hartmanngram.size().height,y2d_image_um);</span>
<a name="269"><font size=-1>269     </font></a><span class="default"></span>
<a name="270"><font size=-1>270     </font></a><span class="default">    cv::Mat u2d_image = y2d_image_um.clone();</span>
<a name="271"><font size=-1>271     </font></a><span class="default">    cv::Mat v2d_image = x2d_image_um.clone();</span>
<a name="272"><font size=-1>272     </font></a><span class="default"></span>
<a name="273"><font size=-1>273     </font></a><span class="default">    x2d_image_um = x2d_image_um * pixel_size * </span><span class="number">1e6</span><span class="default">;</span>
<a name="274"><font size=-1>274     </font></a><span class="default">    y2d_image_um = y2d_image_um * pixel_size * </span><span class="number">1e6</span><span class="default">;</span>
<a name="275"><font size=-1>275     </font></a><span class="default"></span>
<a name="276"><font size=-1>276     </font></a><span class="default">    hartmanngram.convertTo(hartmanngram, CV_64F); </span>
<a name="277"><font size=-1>277     </font></a><span class="default">    cv::Mat OutputArray = hartmanngram.clone();</span>
<a name="278"><font size=-1>278     </font></a><span class="default">    </span><span class="keyword">double </span><span class="default">mat_min_value, mat_max_value;</span>
<a name="279"><font size=-1>279     </font></a><span class="default">    cv::Point min_location, max_location;</span>
<a name="280"><font size=-1>280     </font></a><span class="default"></span>
<a name="281"><font size=-1>281     </font></a><span class="default">    cv::minMaxLoc(OutputArray, &amp;mat_min_value, &amp;mat_max_value, &amp;min_location, &amp;max_location);</span>
<a name="282"><font size=-1>282     </font></a><span class="default">    OutputArray = (OutputArray / mat_max_value) * (pow(</span><span class="number">2</span><span class="default">, </span><span class="number">8</span><span class="default">) - </span><span class="number">1</span><span class="default">);</span>
<a name="283"><font size=-1>283     </font></a><span class="default">    HIOlAB_CXX_14::floor&lt;</span><span class="keyword">double</span><span class="default">&gt;(OutputArray);;</span>
<a name="284"><font size=-1>284     </font></a><span class="default">    OutputArray.convertTo(OutputArray, CV_8U);</span>
<a name="285"><font size=-1>285     </font></a><span class="default"></span>
<a name="286"><font size=-1>286     </font></a><span class="default">    cv::GaussianBlur(OutputArray, OutputArray, cv::Size(</span><span class="number">5</span><span class="default">, </span><span class="number">5</span><span class="default">), </span><span class="number">0</span><span class="default">);</span>
<a name="287"><font size=-1>287     </font></a><span class="default"></span>
<a name="288"><font size=-1>288     </font></a><span class="default">    </span><span class="keyword">switch </span><span class="default">(thresholding_mode) {</span>
<a name="289"><font size=-1>289     </font></a><span class="default">        </span><span class="keyword">case </span><span class="default">HIOlAB_CXX_14::ThresholdMode::Adaptive :</span>
<a name="290"><font size=-1>290     </font></a><span class="default">            cv::adaptiveThreshold(OutputArray, OutputArray,</span><span class="number">255</span><span class="default">,cv::ADAPTIVE_THRESH_GAUSSIAN_C,cv::THRESH_BINARY,block_size,-</span><span class="number">1</span><span class="default">);</span>
<a name="291"><font size=-1>291     </font></a><span class="default">            </span><span class="keyword">break</span><span class="default">;</span>
<a name="292"><font size=-1>292     </font></a><span class="default">        </span><span class="keyword">case </span><span class="default">HIOlAB_CXX_14::ThresholdMode::OTSU:</span>
<a name="293"><font size=-1>293     </font></a><span class="default">            cv::threshold(OutputArray, OutputArray, </span><span class="number">0</span><span class="default">, </span><span class="number">255</span><span class="default">, cv::THRESH_BINARY + cv::THRESH_OTSU);</span>
<a name="294"><font size=-1>294     </font></a><span class="default">            </span><span class="keyword">break</span><span class="default">;</span>
<a name="295"><font size=-1>295     </font></a><span class="default">        </span><span class="keyword">case </span><span class="default">HIOlAB_CXX_14::ThresholdMode::IMG_INT_THR:</span>
<a name="296"><font size=-1>296     </font></a><span class="default">            cv::threshold(OutputArray, OutputArray, img_int_thr, </span><span class="number">255</span><span class="default">, cv::THRESH_BINARY);</span>
<a name="297"><font size=-1>297     </font></a><span class="default">            </span><span class="keyword">break</span><span class="default">;</span>
<a name="298"><font size=-1>298     </font></a><span class="default">        </span><span class="keyword">default</span><span class="default">:</span>
<a name="299"><font size=-1>299     </font></a><span class="default">            cv::adaptiveThreshold(OutputArray, OutputArray, </span><span class="number">255</span><span class="default">, cv::ADAPTIVE_THRESH_GAUSSIAN_C, cv::THRESH_BINARY, block_size, -</span><span class="number">1</span><span class="default">);</span>
<a name="300"><font size=-1>300     </font></a><span class="default">            </span><span class="keyword">break</span><span class="default">;</span>
<a name="301"><font size=-1>301     </font></a><span class="default">    }</span>
<a name="302"><font size=-1>302     </font></a><span class="default"></span>
<a name="303"><font size=-1>303     </font></a><span class="default">    cv::Mat labels,stats, centroids;</span>
<a name="304"><font size=-1>304     </font></a><span class="default">    </span><span class="keyword">int </span><span class="default">numlabels= cv::connectedComponentsWithStats(OutputArray, labels, stats, centroids);</span>
<a name="305"><font size=-1>305     </font></a><span class="default">    infoText-&gt;appendPlainText(QString(u8</span><span class="string">&quot;连通域的数量&quot;</span><span class="default">) + QString::number(numlabels));</span>
<a name="306"><font size=-1>306     </font></a><span class="default">    infoText-&gt;appendPlainText(QString(</span><span class="string">&quot;label shape height width &quot;</span><span class="default">) + QString::number(labels.size().height)+QString(</span><span class="string">&quot; &quot;</span><span class="default">) + QString::number(labels.size().width));</span>
<a name="307"><font size=-1>307     </font></a><span class="default">    infoText-&gt;appendPlainText(QString(</span><span class="string">&quot;stats shape height width &quot;</span><span class="default">) + QString::number(stats.size().height) + QString(</span><span class="string">&quot; &quot;</span><span class="default">) + QString::number(stats.size().width));</span>
<a name="308"><font size=-1>308     </font></a><span class="default">    infoText-&gt;appendPlainText(QString(</span><span class="string">&quot;centroids shape height width &quot;</span><span class="default">) + QString::number(centroids.size().height) + QString(</span><span class="string">&quot; &quot;</span><span class="default">) +QString::number(centroids.size().width));</span>
<a name="309"><font size=-1>309     </font></a><span class="default">    cv::Mat area = stats.col(cv::CC_STAT_AREA);</span>
<a name="310"><font size=-1>310     </font></a><span class="default"></span>
<a name="311"><font size=-1>311     </font></a><span class="default">    </span><span class="comment">//上面的测试全部通过</span>
<a name="312"><font size=-1>312     </font></a><span class="comment">    </span><span class="keyword">int </span><span class="default">num_of_valid_rois = cv::countNonZero(area &gt;= area_thr) - </span><span class="number">1</span><span class="default">;</span>
<a name="313"><font size=-1>313     </font></a><span class="default">    cv::Mat roi_idx_of_valid_rois = cv::Mat::zeros(cv::Size(num_of_valid_rois,</span><span class="number">1</span><span class="default">),CV_32F);</span>
<a name="314"><font size=-1>314     </font></a><span class="default">    num_of_valid_rois = </span><span class="number">0</span><span class="default">;</span>
<a name="315"><font size=-1>315     </font></a><span class="default"></span>
<a name="316"><font size=-1>316     </font></a><span class="default">    </span><span class="comment">//// 标记 如果这里roiidx大于65535时会发生溢出 Error ！！！！</span>
<a name="317"><font size=-1>317     </font></a><span class="comment">    //for (int roi_idx=1;roi_idx&lt;numlabels;roi_idx++) {</span>
<a name="318"><font size=-1>318     </font></a><span class="comment"></span>
<a name="319"><font size=-1>319     </font></a><span class="comment">    //    area.at&lt;int&gt;(roi_idx, 1) &gt;= area_thr ? roi_idx_of_valid_rois.at&lt;int&gt;(num_of_valid_rois++,1)= roi_idx</span>
<a name="320"><font size=-1>320     </font></a><span class="comment">    //                                          : HIOlAB_CXX_14::thresholdProcessing&lt;int&gt;(roi_idx_of_valid_rois,roi_idx);</span>
<a name="321"><font size=-1>321     </font></a><span class="comment">    //}</span>
<a name="322"><font size=-1>322     </font></a><span class="comment"></span>
<a name="323"><font size=-1>323     </font></a><span class="comment"></span>
<a name="324"><font size=-1>324     </font></a><span class="comment">    </span><span class="default">infoText-&gt;appendPlainText(u8</span><span class="string">&quot;Calculating the wrapped phase &quot;</span><span class="default">);</span>
<a name="325"><font size=-1>325     </font></a><span class="default">    cv::Mat u_wrapped_phase(hartmanngram.rows, hartmanngram.cols, CV_64F);</span>
<a name="326"><font size=-1>326     </font></a><span class="default">    cv::Mat u_amplitude(hartmanngram.rows, hartmanngram.cols, CV_64F);</span>
<a name="327"><font size=-1>327     </font></a><span class="default">    cv::Mat v_wrapped_phase(hartmanngram.rows, hartmanngram.cols, CV_64F);</span>
<a name="328"><font size=-1>328     </font></a><span class="default">    cv::Mat v_amplitude(hartmanngram.rows, hartmanngram.cols, CV_64F);</span>
<a name="329"><font size=-1>329     </font></a><span class="default">    calculateWrappedPhasesUV(hartmanngram, u2d_image, v2d_image, min_fringle_number,u_wrapped_phase,u_amplitude,v_wrapped_phase,v_amplitude);</span>
<a name="330"><font size=-1>330     </font></a><span class="default"></span>
<a name="331"><font size=-1>331     </font></a><span class="default">    </span><span class="comment">//! 2023 11-29 </span>
<a name="332"><font size=-1>332     </font></a><span class="comment">    </span><span class="default">cv::Mat quality_image = (u_amplitude + v_amplitude) / </span><span class="number">2</span><span class="default">;</span>
<a name="333"><font size=-1>333     </font></a><span class="default">    cv::minMaxLoc(quality_image, &amp;mat_min_value, &amp;mat_max_value, &amp;min_location, &amp;max_location);</span>
<a name="334"><font size=-1>334     </font></a><span class="default">    quality_image =((quality_image - mat_max_value) / (mat_max_value - mat_min_value))*</span><span class="number">255</span><span class="default">;</span>
<a name="335"><font size=-1>335     </font></a><span class="default">    quality_image.convertTo(quality_image, CV_8U);</span>
<a name="336"><font size=-1>336     </font></a><span class="default">    cv::threshold(quality_image, quality_image, </span><span class="number">0</span><span class="default">, </span><span class="number">1</span><span class="default">, cv::THRESH_OTSU);</span>
<a name="337"><font size=-1>337     </font></a><span class="default">    cv::Mat searching_mask = (quality_image &gt;= </span><span class="number">0</span><span class="default">) / </span><span class="number">255</span><span class="default">;</span>
<a name="338"><font size=-1>338     </font></a><span class="default"></span>
<a name="339"><font size=-1>339     </font></a><span class="default">    </span><span class="keyword">if </span><span class="default">(starting_pixel.empty()) {</span>
<a name="340"><font size=-1>340     </font></a><span class="default">        cv::Mat centroid_u(u2d_image.rows, u2d_image.cols, CV_64F);</span>
<a name="341"><font size=-1>341     </font></a><span class="default">        cv::Mat centroid_v(v2d_image.rows, v2d_image.cols, CV_64F);</span>
<a name="342"><font size=-1>342     </font></a><span class="default"></span>
<a name="343"><font size=-1>343     </font></a><span class="default">        </span><span class="keyword">try</span><span class="default">{</span>
<a name="344"><font size=-1>344     </font></a><span class="default"></span>
<a name="345"><font size=-1>345     </font></a><span class="default">            u2d_image.convertTo(u2d_image, CV_64F);</span>
<a name="346"><font size=-1>346     </font></a><span class="default">            u2d_image.convertTo(v2d_image, CV_64F);</span>
<a name="347"><font size=-1>347     </font></a><span class="default">            quality_image.convertTo(quality_image, CV_64F);</span>
<a name="348"><font size=-1>348     </font></a><span class="default">            </span><span class="comment">//注意数据类型 这里的逻辑对 但是每个矩阵的的类型不一样 在调试的时候要进行修改</span>
<a name="349"><font size=-1>349     </font></a><span class="comment">            </span><span class="default">calculateCentroid(quality_image, u2d_image, v2d_image, centroid_u, centroid_v);</span>
<a name="350"><font size=-1>350     </font></a><span class="default">        }</span>
<a name="351"><font size=-1>351     </font></a><span class="default">        </span><span class="keyword">catch </span><span class="default">(</span><span class="keyword">const </span><span class="default">std::exception&amp; matNullException){</span>
<a name="352"><font size=-1>352     </font></a><span class="default"></span>
<a name="353"><font size=-1>353     </font></a><span class="default">            HIOlAB_CXX_14::ExceptionInfoPrint(matNullException.what());</span>
<a name="354"><font size=-1>354     </font></a><span class="default">        }</span>
<a name="355"><font size=-1>355     </font></a><span class="default">        </span>
<a name="356"><font size=-1>356     </font></a><span class="default">        cv::Scalar  area = cv::sum(quality_image*</span><span class="number">1</span><span class="default">);</span>
<a name="357"><font size=-1>357     </font></a><span class="default">        </span><span class="keyword">float </span><span class="default">r_thr      = sqrt(area[</span><span class="number">0</span><span class="default">] / M_PI) / </span><span class="number">2</span><span class="default">;</span>
<a name="358"><font size=-1>358     </font></a><span class="default">        cv::Mat r_2d(u2d_image.rows, u2d_image.cols, centroid_u.type());</span>
<a name="359"><font size=-1>359     </font></a><span class="default">        cv::Mat_&lt;</span><span class="keyword">bool</span><span class="default">&gt; searching_mask = (r_2d &lt; searching_mask) / </span><span class="number">255</span><span class="default">;</span>
<a name="360"><font size=-1>360     </font></a><span class="default">        cv::Mat result(quality_image.rows, quality_image.cols, quality_image.type());</span>
<a name="361"><font size=-1>361     </font></a><span class="default"></span>
<a name="362"><font size=-1>362     </font></a><span class="default">        </span><span class="keyword">try</span><span class="default">{</span>
<a name="363"><font size=-1>363     </font></a><span class="default">            </span>
<a name="364"><font size=-1>364     </font></a><span class="default">            HIOlAB_CXX_14::booleanArrayIndexing&lt;</span><span class="keyword">double</span><span class="default">&gt;(quality_image, searching_mask, result);</span>
<a name="365"><font size=-1>365     </font></a><span class="default">            cv::minMaxLoc(result, &amp;mat_min_value, &amp;mat_max_value, &amp;min_location, &amp;max_location);</span>
<a name="366"><font size=-1>366     </font></a><span class="default">            HIOlAB_CXX_14::where&lt;</span><span class="keyword">double</span><span class="default">&gt;(quality_image, mat_min_value,starting_pixel);</span>
<a name="367"><font size=-1>367     </font></a><span class="default">        }</span>
<a name="368"><font size=-1>368     </font></a><span class="default">        </span><span class="keyword">catch </span><span class="default">(</span><span class="keyword">const </span><span class="default">std::exception&amp; matNullException){</span>
<a name="369"><font size=-1>369     </font></a><span class="default"></span>
<a name="370"><font size=-1>370     </font></a><span class="default">            HIOlAB_CXX_14::ExceptionInfoPrint(matNullException.what());</span>
<a name="371"><font size=-1>371     </font></a><span class="default">        }</span>
<a name="372"><font size=-1>372     </font></a><span class="default">    }</span>
<a name="373"><font size=-1>373     </font></a><span class="default">}</span>
<a name="374"><font size=-1>374     </font></a><span class="default"></span>
<a name="375"><font size=-1>375     </font></a><span class="default"></span>
<a name="376"><font size=-1>376     </font></a><span class="default"></span><span class="keyword">bool  </span><span class="default">WaveFrontSensor::FFT_Shift(cv::Mat&amp; source,cv::Mat&amp; CV_Shift_Mat) {</span>
<a name="377"><font size=-1>377     </font></a><span class="default">    </span>
<a name="378"><font size=-1>378     </font></a><span class="default">    </span><span class="keyword">int </span><span class="default">cx = source.cols / </span><span class="number">2</span><span class="default">;</span>
<a name="379"><font size=-1>379     </font></a><span class="default">    </span><span class="keyword">int </span><span class="default">cy = source.rows / </span><span class="number">2</span><span class="default">;</span>
<a name="380"><font size=-1>380     </font></a><span class="default"></span>
<a name="381"><font size=-1>381     </font></a><span class="default">    cv::Mat Block_0(source, cv::Rect(</span><span class="number">0</span><span class="default">, </span><span class="number">0</span><span class="default">, cx, cy));</span>
<a name="382"><font size=-1>382     </font></a><span class="default">    cv::Mat Block_1(source, cv::Rect(cx, </span><span class="number">0</span><span class="default">, cx, cy));</span>
<a name="383"><font size=-1>383     </font></a><span class="default">    cv::Mat Block_2(source, cv::Rect(</span><span class="number">0</span><span class="default">, cy, cx, cy));</span>
<a name="384"><font size=-1>384     </font></a><span class="default">    cv::Mat Block_3(source, cv::Rect(cx, cy, cx, cy));</span>
<a name="385"><font size=-1>385     </font></a><span class="default">    </span>
<a name="386"><font size=-1>386     </font></a><span class="default">    Block_0.copyTo(CV_Shift_Mat);</span>
<a name="387"><font size=-1>387     </font></a><span class="default">    Block_3.copyTo(Block_0);</span>
<a name="388"><font size=-1>388     </font></a><span class="default">    CV_Shift_Mat.copyTo(Block_3);</span>
<a name="389"><font size=-1>389     </font></a><span class="default"></span>
<a name="390"><font size=-1>390     </font></a><span class="default">    Block_1.copyTo(CV_Shift_Mat);</span>
<a name="391"><font size=-1>391     </font></a><span class="default">    Block_2.copyTo(Block_1);</span>
<a name="392"><font size=-1>392     </font></a><span class="default">    CV_Shift_Mat.copyTo(Block_2);</span>
<a name="393"><font size=-1>393     </font></a><span class="default"></span>
<a name="394"><font size=-1>394     </font></a><span class="default">    CV_Shift_Mat = source;</span>
<a name="395"><font size=-1>395     </font></a><span class="default">    </span><span class="keyword">return </span><span class="default">CV_Shift_Mat.empty() ? </span><span class="keyword">throw </span><span class="default">FftException(</span><span class="string">&quot;FFT Shift Exception&quot;</span><span class="default">) : </span><span class="keyword">true</span><span class="default">;</span>
<a name="396"><font size=-1>396     </font></a><span class="default">}</span>
<a name="397"><font size=-1>397     </font></a><span class="default"></span>
<a name="398"><font size=-1>398     </font></a><span class="default"></span>
<a name="399"><font size=-1>399     </font></a><span class="default"></span>
<a name="400"><font size=-1>400     </font></a><span class="default"></span>
<a name="401"><font size=-1>401     </font></a><span class="default"></span><span class="keyword">bool  </span><span class="default">WaveFrontSensor::FFT1(cv::Mat&amp; InputArray, cv::Mat&amp; OutputArray) {</span>
<a name="402"><font size=-1>402     </font></a><span class="default"></span>
<a name="403"><font size=-1>403     </font></a><span class="default">    cv::dft(InputArray, OutputArray,cv::DFT_COMPLEX_OUTPUT);</span>
<a name="404"><font size=-1>404     </font></a><span class="default">    FFT_Shift(OutputArray,OutputArray);</span>
<a name="405"><font size=-1>405     </font></a><span class="default">    </span><span class="keyword">return </span><span class="default">OutputArray.empty() ? </span><span class="keyword">throw </span><span class="default">FftException(</span><span class="string">&quot;FFT1 Calculate Exception &quot;</span><span class="default">) : </span><span class="keyword">true</span><span class="default">;</span>
<a name="406"><font size=-1>406     </font></a><span class="default">}</span>
<a name="407"><font size=-1>407     </font></a><span class="default"></span>
<a name="408"><font size=-1>408     </font></a><span class="default"></span>
<a name="409"><font size=-1>409     </font></a><span class="default"></span>
<a name="410"><font size=-1>410     </font></a><span class="default"></span><span class="keyword">bool </span><span class="default">WaveFrontSensor::FFT2(cv::Mat&amp; InputArray ,cv::Mat&amp;  OutputArray) {</span>
<a name="411"><font size=-1>411     </font></a><span class="default"></span>
<a name="412"><font size=-1>412     </font></a><span class="default">    </span><span class="keyword">int </span><span class="default">rows    = InputArray.rows;</span>
<a name="413"><font size=-1>413     </font></a><span class="default">    </span><span class="keyword">int </span><span class="default">columns = InputArray.cols;</span>
<a name="414"><font size=-1>414     </font></a><span class="default">    </span><span class="keyword">int </span><span class="default">row_padded = cv::getOptimalDFTSize(rows);</span>
<a name="415"><font size=-1>415     </font></a><span class="default">    </span><span class="keyword">int </span><span class="default">col_padded = cv::getOptimalDFTSize(columns);</span>
<a name="416"><font size=-1>416     </font></a><span class="default">    cv::Mat padded_mat;</span>
<a name="417"><font size=-1>417     </font></a><span class="default">    cv::copyMakeBorder(InputArray, padded_mat, </span><span class="number">0</span><span class="default">, row_padded - InputArray.rows, </span><span class="number">0</span><span class="default">, col_padded - InputArray.cols, cv::BORDER_CONSTANT, cv::Scalar::all(</span><span class="number">0</span><span class="default">));</span>
<a name="418"><font size=-1>418     </font></a><span class="default">    cv::Mat planes[] = { cv::Mat_&lt;</span><span class="keyword">double</span><span class="default">&gt;(padded_mat),cv::Mat::zeros(padded_mat.size(),CV_64F) };</span>
<a name="419"><font size=-1>419     </font></a><span class="default">    cv::Mat     complexl;</span>
<a name="420"><font size=-1>420     </font></a><span class="default">    cv::merge(planes, </span><span class="number">2</span><span class="default">, complexl);</span>
<a name="421"><font size=-1>421     </font></a><span class="default">    cv::dft(complexl, complexl,cv::DFT_COMPLEX_OUTPUT);</span>
<a name="422"><font size=-1>422     </font></a><span class="default"></span>
<a name="423"><font size=-1>423     </font></a><span class="default">    </span><span class="keyword">try</span><span class="default">{</span>
<a name="424"><font size=-1>424     </font></a><span class="default">        FFT_Shift(complexl, OutputArray);</span>
<a name="425"><font size=-1>425     </font></a><span class="default">    }</span>
<a name="426"><font size=-1>426     </font></a><span class="default">    </span><span class="keyword">catch </span><span class="default">(</span><span class="keyword">const </span><span class="default">std::exception&amp; fftException){</span>
<a name="427"><font size=-1>427     </font></a><span class="default"></span>
<a name="428"><font size=-1>428     </font></a><span class="default">        HIOlAB_CXX_14::ExceptionInfoPrint(fftException.what());</span>
<a name="429"><font size=-1>429     </font></a><span class="default">    }</span>
<a name="430"><font size=-1>430     </font></a><span class="default"></span>
<a name="431"><font size=-1>431     </font></a><span class="default">    </span><span class="keyword">return </span><span class="default">OutputArray.empty() ? </span><span class="keyword">throw </span><span class="default">FftException(</span><span class="string">&quot;FFT2 Calculate Exception &quot;</span><span class="default">) : </span><span class="keyword">true</span><span class="default">;</span>
<a name="432"><font size=-1>432     </font></a><span class="default">}</span>
<a name="433"><font size=-1>433     </font></a><span class="default"></span>
<a name="434"><font size=-1>434     </font></a><span class="default"></span>
<a name="435"><font size=-1>435     </font></a><span class="default"></span><span class="keyword">bool </span><span class="default">WaveFrontSensor::IFFT(cv::Mat&amp; InputArray, cv::Mat&amp; OutputArray) {</span>
<a name="436"><font size=-1>436     </font></a><span class="default"></span>
<a name="437"><font size=-1>437     </font></a><span class="default">    cv::idft(InputArray, OutputArray, cv::DFT_COMPLEX_INPUT | cv::DFT_SCALE);</span>
<a name="438"><font size=-1>438     </font></a><span class="default">    </span><span class="keyword">return </span><span class="default">OutputArray.empty() ? </span><span class="keyword">throw </span><span class="default">FftException(</span><span class="string">&quot;IFFT Calculate Exception &quot;</span><span class="default">) : </span><span class="keyword">true</span><span class="default">;</span>
<a name="439"><font size=-1>439     </font></a><span class="default">}</span>
<a name="440"><font size=-1>440     </font></a><span class="default"></span>
<a name="441"><font size=-1>441     </font></a><span class="default"></span>
<a name="442"><font size=-1>442     </font></a><span class="default"></span>
<a name="443"><font size=-1>443     </font></a><span class="default"></span>
<a name="444"><font size=-1>444     </font></a><span class="default"></span>
<a name="445"><font size=-1>445     </font></a><span class="default"></span><span class="keyword">void </span><span class="default">WaveFrontSensor::IFFT_Shift(cv::Mat&amp; source) {</span>
<a name="446"><font size=-1>446     </font></a><span class="default"></span>
<a name="447"><font size=-1>447     </font></a><span class="default">    </span><span class="keyword">int </span><span class="default">cx = source.cols / </span><span class="number">2</span><span class="default">;</span>
<a name="448"><font size=-1>448     </font></a><span class="default">    </span><span class="keyword">int </span><span class="default">cy = source.rows / </span><span class="number">2</span><span class="default">;</span>
<a name="449"><font size=-1>449     </font></a><span class="default"></span>
<a name="450"><font size=-1>450     </font></a><span class="default">    cv::Mat q0(source, cv::Rect(</span><span class="number">0</span><span class="default">, </span><span class="number">0</span><span class="default">, cx, cy)); </span>
<a name="451"><font size=-1>451     </font></a><span class="default">    cv::Mat q1(source, cv::Rect(cx, </span><span class="number">0</span><span class="default">, cx, cy)); </span>
<a name="452"><font size=-1>452     </font></a><span class="default">    cv::Mat q2(source, cv::Rect(</span><span class="number">0</span><span class="default">, cy, cx, cy)); </span>
<a name="453"><font size=-1>453     </font></a><span class="default">    cv::Mat q3(source, cv::Rect(cx, cy, cx, cy));</span>
<a name="454"><font size=-1>454     </font></a><span class="default"></span>
<a name="455"><font size=-1>455     </font></a><span class="default">    cv::Mat tmp; </span>
<a name="456"><font size=-1>456     </font></a><span class="default"></span>
<a name="457"><font size=-1>457     </font></a><span class="default">    q0.copyTo(tmp);</span>
<a name="458"><font size=-1>458     </font></a><span class="default">    q3.copyTo(q0);</span>
<a name="459"><font size=-1>459     </font></a><span class="default">    tmp.copyTo(q3);</span>
<a name="460"><font size=-1>460     </font></a><span class="default"></span>
<a name="461"><font size=-1>461     </font></a><span class="default">    q1.copyTo(tmp);</span>
<a name="462"><font size=-1>462     </font></a><span class="default">    q2.copyTo(q1);</span>
<a name="463"><font size=-1>463     </font></a><span class="default">    tmp.copyTo(q2);</span>
<a name="464"><font size=-1>464     </font></a><span class="default">}</span>
<a name="465"><font size=-1>465     </font></a><span class="default"></span>
<a name="466"><font size=-1>466     </font></a><span class="default"></span>
<a name="467"><font size=-1>467     </font></a><span class="default"></span>
<a name="468"><font size=-1>468     </font></a><span class="default"></span><span class="comment">/** 存在问题 定义的变量mat太多了 解决 能不能复用？ */</span>
<a name="469"><font size=-1>469     </font></a><span class="comment"></span>
<a name="470"><font size=-1>470     </font></a><span class="comment"></span><span class="keyword">void </span><span class="default">WaveFrontSensor::calculateWrappedPhase(cv::Mat&amp; spectrum, cv::Mat&amp; u2d_img, cv::Mat&amp; v2d_img, </span><span class="keyword">int </span><span class="default">min_fringe_number, cv::Mat&amp; wrapped_phase, cv::Mat&amp; amplitude, </span><span class="keyword">bool </span><span class="default">is_u) {</span>
<a name="471"><font size=-1>471     </font></a><span class="default"></span>
<a name="472"><font size=-1>472     </font></a><span class="default">        cv::Point2f center(</span><span class="keyword">static_cast</span><span class="default">&lt;</span><span class="keyword">double</span><span class="default">&gt;(spectrum.cols) / </span><span class="number">2</span><span class="default">, </span><span class="keyword">static_cast</span><span class="default">&lt;</span><span class="keyword">double</span><span class="default">&gt;(spectrum.rows) / </span><span class="number">2</span><span class="default">);</span>
<a name="473"><font size=-1>473     </font></a><span class="default">        u2d_img.convertTo(u2d_img, CV_64F);</span>
<a name="474"><font size=-1>474     </font></a><span class="default">        v2d_img.convertTo(v2d_img, CV_64F);</span>
<a name="475"><font size=-1>475     </font></a><span class="default">        cv::Mat un2d = u2d_img - center.x;</span>
<a name="476"><font size=-1>476     </font></a><span class="default">        cv::Mat vn2d = v2d_img - center.y;</span>
<a name="477"><font size=-1>477     </font></a><span class="default">        cv::Mat planes[</span><span class="number">2</span><span class="default">];</span>
<a name="478"><font size=-1>478     </font></a><span class="default">        cv::split(spectrum, planes);</span>
<a name="479"><font size=-1>479     </font></a><span class="default"></span>
<a name="480"><font size=-1>480     </font></a><span class="default">        cv::magnitude(planes[</span><span class="number">0</span><span class="default">], planes[</span><span class="number">1</span><span class="default">], planes[</span><span class="number">0</span><span class="default">]);</span>
<a name="481"><font size=-1>481     </font></a><span class="default">        cv::Mat amp = planes[</span><span class="number">0</span><span class="default">];</span>
<a name="482"><font size=-1>482     </font></a><span class="default"></span>
<a name="483"><font size=-1>483     </font></a><span class="default">        cv::Mat_&lt;</span><span class="keyword">double</span><span class="default">&gt; (rn2d);</span>
<a name="484"><font size=-1>484     </font></a><span class="default">        cv::sqrt(un2d.mul(un2d) + vn2d.mul(vn2d), rn2d);</span>
<a name="485"><font size=-1>485     </font></a><span class="default">  </span>
<a name="486"><font size=-1>486     </font></a><span class="default">        cv::Mat_&lt;</span><span class="keyword">bool</span><span class="default">&gt;(r_mask);</span>
<a name="487"><font size=-1>487     </font></a><span class="default">        r_mask = (rn2d &gt; min_fringe_number)/</span><span class="number">255</span><span class="default">;</span>
<a name="488"><font size=-1>488     </font></a><span class="default">        </span>
<a name="489"><font size=-1>489     </font></a><span class="default">        cv::Mat_&lt;</span><span class="keyword">bool</span><span class="default">&gt;(uv_mask);</span>
<a name="490"><font size=-1>490     </font></a><span class="default">        is_u==</span><span class="keyword">true </span><span class="default">? (uv_mask = ((vn2d &lt; un2d)/</span><span class="number">255</span><span class="default">) &amp; ((vn2d &gt; -un2d))/</span><span class="number">255</span><span class="default">) : (uv_mask = ((vn2d &gt; un2d)/</span><span class="number">255</span><span class="default">) &amp; ((vn2d &gt; -un2d)/</span><span class="number">255</span><span class="default">));</span>
<a name="491"><font size=-1>491     </font></a><span class="default"></span>
<a name="492"><font size=-1>492     </font></a><span class="default">        cv::Mat ruv_mask = r_mask &amp; uv_mask;</span>
<a name="493"><font size=-1>493     </font></a><span class="default">        ruv_mask.convertTo(ruv_mask, CV_64F);</span>
<a name="494"><font size=-1>494     </font></a><span class="default">        cv::Mat filtered_amp = amp.mul(ruv_mask);</span>
<a name="495"><font size=-1>495     </font></a><span class="default"></span>
<a name="496"><font size=-1>496     </font></a><span class="default">        cv::Point maxLoc;</span>
<a name="497"><font size=-1>497     </font></a><span class="default">        cv::minMaxLoc(filtered_amp, nullptr, nullptr, nullptr, &amp;maxLoc);</span>
<a name="498"><font size=-1>498     </font></a><span class="default"></span>
<a name="499"><font size=-1>499     </font></a><span class="default">        cv::Point2i uc, vc;</span>
<a name="500"><font size=-1>500     </font></a><span class="default">        uc = maxLoc;</span>
<a name="501"><font size=-1>501     </font></a><span class="default">        vc = maxLoc;</span>
<a name="502"><font size=-1>502     </font></a><span class="default"></span>
<a name="503"><font size=-1>503     </font></a><span class="default">        </span><span class="keyword">int </span><span class="default">uc_half = </span><span class="keyword">static_cast</span><span class="default">&lt;</span><span class="keyword">int</span><span class="default">&gt;(std::floor((uc.x - center.x) / </span><span class="number">2 </span><span class="default">+ center.x));</span>
<a name="504"><font size=-1>504     </font></a><span class="default">        </span><span class="keyword">int </span><span class="default">vc_half = </span><span class="keyword">static_cast</span><span class="default">&lt;</span><span class="keyword">int</span><span class="default">&gt;(std::floor((vc.y - center.y) / </span><span class="number">2 </span><span class="default">+ center.y));</span>
<a name="505"><font size=-1>505     </font></a><span class="default"></span>
<a name="506"><font size=-1>506     </font></a><span class="default">        </span><span class="keyword">if </span><span class="default">(filtered_amp.at&lt;</span><span class="keyword">double</span><span class="default">&gt;(vc.y, uc.x) &lt; </span><span class="number">3 </span><span class="default">* filtered_amp.at&lt;</span><span class="keyword">double</span><span class="default">&gt;(vc_half, uc_half)) {</span>
<a name="507"><font size=-1>507     </font></a><span class="default">            uc.x = uc_half;</span>
<a name="508"><font size=-1>508     </font></a><span class="default">            vc.y = vc_half;</span>
<a name="509"><font size=-1>509     </font></a><span class="default">        }</span>
<a name="510"><font size=-1>510     </font></a><span class="default"></span>
<a name="511"><font size=-1>511     </font></a><span class="default">        cv::Mat unc = cv::Mat(</span><span class="number">1</span><span class="default">, </span><span class="number">1</span><span class="default">, CV_64F, </span><span class="keyword">static_cast</span><span class="default">&lt;</span><span class="keyword">double</span><span class="default">&gt;(uc.x) - center.x);</span>
<a name="512"><font size=-1>512     </font></a><span class="default">        cv::Mat vnc = cv::Mat(</span><span class="number">1</span><span class="default">, </span><span class="number">1</span><span class="default">, CV_64F, </span><span class="keyword">static_cast</span><span class="default">&lt;</span><span class="keyword">double</span><span class="default">&gt;(vc.y) - center.y);</span>
<a name="513"><font size=-1>513     </font></a><span class="default"></span>
<a name="514"><font size=-1>514     </font></a><span class="default">        </span><span class="keyword">double </span><span class="default">r_thr = rn2d.at&lt;</span><span class="keyword">double</span><span class="default">&gt;(vc.y, uc.x) / </span><span class="number">4</span><span class="default">;</span>
<a name="515"><font size=-1>515     </font></a><span class="default">        cv::pow(un2d - unc, </span><span class="number">2</span><span class="default">, un2d);</span>
<a name="516"><font size=-1>516     </font></a><span class="default">        cv::pow(vn2d - vnc, </span><span class="number">2</span><span class="default">, vn2d);</span>
<a name="517"><font size=-1>517     </font></a><span class="default">        cv::sqrt(un2d+vn2d,un2d);</span>
<a name="518"><font size=-1>518     </font></a><span class="default">        cv::Mat rc2d = un2d;</span>
<a name="519"><font size=-1>519     </font></a><span class="default">        cv::Mat mask= (rc2d &lt; r_thr) / </span><span class="number">255</span><span class="default">;</span>
<a name="520"><font size=-1>520     </font></a><span class="default">        mask.convertTo(mask, CV_64F);</span>
<a name="521"><font size=-1>521     </font></a><span class="default">        cv::Mat filtered_complex_img(spectrum.rows, spectrum.cols,spectrum.type());</span>
<a name="522"><font size=-1>522     </font></a><span class="default">        std::vector&lt;cv::Mat&gt; channels;</span>
<a name="523"><font size=-1>523     </font></a><span class="default">        cv::split(spectrum, channels);</span>
<a name="524"><font size=-1>524     </font></a><span class="default">        cv::Mat real = channels[</span><span class="number">0</span><span class="default">].mul(mask);</span>
<a name="525"><font size=-1>525     </font></a><span class="default">        cv::Mat imag = channels[</span><span class="number">1</span><span class="default">].mul(mask);</span>
<a name="526"><font size=-1>526     </font></a><span class="default">        cv::Mat plans[] = { real,imag };</span>
<a name="527"><font size=-1>527     </font></a><span class="default"></span>
<a name="528"><font size=-1>528     </font></a><span class="default">        cv::merge(plans,</span><span class="number">2</span><span class="default">,filtered_complex_img);</span>
<a name="529"><font size=-1>529     </font></a><span class="default"></span>
<a name="530"><font size=-1>530     </font></a><span class="default">        cv::Mat shift_filter_complex_img=filtered_complex_img.clone();</span>
<a name="531"><font size=-1>531     </font></a><span class="default">        cv::Mat ifft_result_mat(shift_filter_complex_img.rows,shift_filter_complex_img.cols,shift_filter_complex_img.type());</span>
<a name="532"><font size=-1>532     </font></a><span class="default"></span>
<a name="533"><font size=-1>533     </font></a><span class="default">        </span><span class="keyword">try</span><span class="default">{</span>
<a name="534"><font size=-1>534     </font></a><span class="default">            IFFT_Shift(shift_filter_complex_img);</span>
<a name="535"><font size=-1>535     </font></a><span class="default">            IFFT(shift_filter_complex_img, ifft_result_mat);</span>
<a name="536"><font size=-1>536     </font></a><span class="default">        }</span>
<a name="537"><font size=-1>537     </font></a><span class="default">        </span><span class="keyword">catch </span><span class="default">(</span><span class="keyword">const </span><span class="default">std::exception&amp; fftException){</span>
<a name="538"><font size=-1>538     </font></a><span class="default"></span>
<a name="539"><font size=-1>539     </font></a><span class="default">            HIOlAB_CXX_14::ExceptionInfoPrint(fftException.what());</span>
<a name="540"><font size=-1>540     </font></a><span class="default">        }</span>
<a name="541"><font size=-1>541     </font></a><span class="default"></span>
<a name="542"><font size=-1>542     </font></a><span class="default"></span>
<a name="543"><font size=-1>543     </font></a><span class="default">        cv::split(ifft_result_mat,plans);</span>
<a name="544"><font size=-1>544     </font></a><span class="default">        HIOlAB_CXX_14::angle&lt;</span><span class="keyword">double</span><span class="default">&gt;(plans[</span><span class="number">0</span><span class="default">], plans[</span><span class="number">1</span><span class="default">], wrapped_phase);</span>
<a name="545"><font size=-1>545     </font></a><span class="default"></span>
<a name="546"><font size=-1>546     </font></a><span class="default">        cv::pow(plans[</span><span class="number">0</span><span class="default">], </span><span class="number">2</span><span class="default">, plans[</span><span class="number">0</span><span class="default">]);</span>
<a name="547"><font size=-1>547     </font></a><span class="default">        cv::pow(plans[</span><span class="number">1</span><span class="default">], </span><span class="number">2</span><span class="default">, plans[</span><span class="number">1</span><span class="default">]);</span>
<a name="548"><font size=-1>548     </font></a><span class="default">        cv::sqrt(plans[</span><span class="number">0</span><span class="default">] + plans[</span><span class="number">1</span><span class="default">], amplitude);</span>
<a name="549"><font size=-1>549     </font></a><span class="default">}</span>
<a name="550"><font size=-1>550     </font></a><span class="default"></span>
<a name="551"><font size=-1>551     </font></a><span class="default"></span>
<a name="552"><font size=-1>552     </font></a><span class="default"></span>
<a name="553"><font size=-1>553     </font></a><span class="default"></span>
<a name="554"><font size=-1>554     </font></a><span class="default"></span><span class="keyword">void </span><span class="default">WaveFrontSensor::calculateWrappedPhasesUV(cv::Mat&amp;hartmanngram, cv::Mat&amp;u2d_image, cv::Mat&amp; v2d_image, </span>
<a name="555"><font size=-1>555     </font></a><span class="default">                                                 </span><span class="keyword">int </span><span class="default">min_fringe_number,</span>
<a name="556"><font size=-1>556     </font></a><span class="default">                                                 cv::Mat&amp; u_wrapped_phase,cv::Mat&amp; u_amplitude,cv::Mat&amp; v_wrapped_phase,cv::Mat&amp; v_amplitude ) {</span>
<a name="557"><font size=-1>557     </font></a><span class="default">    cv::Mat  spectrum;</span>
<a name="558"><font size=-1>558     </font></a><span class="default"></span>
<a name="559"><font size=-1>559     </font></a><span class="default">    </span><span class="keyword">try</span><span class="default">{</span>
<a name="560"><font size=-1>560     </font></a><span class="default"></span>
<a name="561"><font size=-1>561     </font></a><span class="default">        FFT2(hartmanngram, spectrum);</span>
<a name="562"><font size=-1>562     </font></a><span class="default">    }</span>
<a name="563"><font size=-1>563     </font></a><span class="default">    </span><span class="keyword">catch </span><span class="default">(</span><span class="keyword">const </span><span class="default">std::exception&amp; fftException){</span>
<a name="564"><font size=-1>564     </font></a><span class="default"></span>
<a name="565"><font size=-1>565     </font></a><span class="default">        HIOlAB_CXX_14::ExceptionInfoPrint(fftException.what());</span>
<a name="566"><font size=-1>566     </font></a><span class="default"></span>
<a name="567"><font size=-1>567     </font></a><span class="default">    }</span>
<a name="568"><font size=-1>568     </font></a><span class="default"></span>
<a name="569"><font size=-1>569     </font></a><span class="default">    calculateWrappedPhase(spectrum,u2d_image,v2d_image,min_fringe_number,u_wrapped_phase,u_amplitude,</span><span class="keyword">true</span><span class="default">);</span>
<a name="570"><font size=-1>570     </font></a><span class="default">    calculateWrappedPhase(spectrum, u2d_image, v2d_image, min_fringe_number, v_wrapped_phase, v_amplitude, </span><span class="keyword">false</span><span class="default">);</span>
<a name="571"><font size=-1>571     </font></a><span class="default">    HIOlAB_CXX_14::Print_Matrix&lt;</span><span class="keyword">double</span><span class="default">&gt;(v_wrapped_phase);</span>
<a name="572"><font size=-1>572     </font></a><span class="default">    HIOlAB_CXX_14::Print_Matrix&lt;</span><span class="keyword">double</span><span class="default">&gt;(v_amplitude);</span>
<a name="573"><font size=-1>573     </font></a><span class="default"></span>
<a name="574"><font size=-1>574     </font></a><span class="default"></span>
<a name="575"><font size=-1>575     </font></a><span class="default">}</span>
<a name="576"><font size=-1>576     </font></a><span class="default"></span>
<a name="577"><font size=-1>577     </font></a><span class="default"></span>
<a name="578"><font size=-1>578     </font></a><span class="default"></span><span class="keyword">void </span><span class="default">WaveFrontSensor::calculateCentroid(cv::Mat&amp; quality_img_bw, cv::Mat&amp; u2d_image, cv::Mat&amp;v2d_image, cv::Mat&amp;centroid_u, cv::Mat&amp; centroid_v) {</span>
<a name="579"><font size=-1>579     </font></a><span class="default"></span>
<a name="580"><font size=-1>580     </font></a><span class="default"></span>
<a name="581"><font size=-1>581     </font></a><span class="default"></span>
<a name="582"><font size=-1>582     </font></a><span class="default">}</span>
<a name="583"><font size=-1>583     </font></a><span class="default"></span>
<a name="584"><font size=-1>584     </font></a><span class="default"></span>
<a name="585"><font size=-1>585     </font></a><span class="default"></span>
<a name="586"><font size=-1>586     </font></a><span class="default"></span>
<a name="587"><font size=-1>587     </font></a><span class="default"></span>
<a name="588"><font size=-1>588     </font></a><span class="default"></span><span class="comment">/**</span>
<a name="589"><font size=-1>589     </font></a><span class="comment"> * .</span>
<a name="590"><font size=-1>590     </font></a><span class="comment"> * \param configuration      配置文件</span>
<a name="591"><font size=-1>591     </font></a><span class="comment"> * \param hartmanngram       待处理的Hartmanngram 图像</span>
<a name="592"><font size=-1>592     </font></a><span class="comment"> * \param starting_pixel     解包</span>
<a name="593"><font size=-1>593     </font></a><span class="comment"> * \param thresholding_model 二值化模式 默认使用自适应二值化</span>
<a name="594"><font size=-1>594     </font></a><span class="comment"> * \param img_int_thr        用来过滤掉信噪比低的像素点                默认0</span>
<a name="595"><font size=-1>595     </font></a><span class="comment"> * \param area_thr           面积阈值 过滤掉面积较小的连通域           默认1</span>
<a name="596"><font size=-1>596     </font></a><span class="comment"> * \param ration_thr         强度体积比阈值 用来过滤宽高比小的连通域   默认0.05</span>
<a name="597"><font size=-1>597     </font></a><span class="comment"> * \param min_order_u        水平方向上拟合多项式的最小阶数            默认2</span>
<a name="598"><font size=-1>598     </font></a><span class="comment"> * \param max_order_u        水平方向上的拟合多项式的最大阶数          默认4</span>
<a name="599"><font size=-1>599     </font></a><span class="comment"> * \param min_order_v        垂直方向上的拟合多项式的最小阶数          默认2</span>
<a name="600"><font size=-1>600     </font></a><span class="comment"> * \param max_order_v        垂直方向上的拟合多项式的最大阶数          默认4</span>
<a name="601"><font size=-1>601     </font></a><span class="comment"> * \param edge_exclusion     排除靠近图像边缘的连通域的边缘宽度        默认1</span>
<a name="602"><font size=-1>602     </font></a><span class="comment"> */</span>
<a name="603"><font size=-1>603     </font></a><span class="comment"></span><span class="keyword">void </span><span class="default">WaveFrontSensor::processHartmanngram(Configuration&amp; configuration, cv::Mat&amp; hartmanngram, cv::Mat starting_pixel,</span>
<a name="604"><font size=-1>604     </font></a><span class="default">    HIOlAB_CXX_14::ThresholdMode thresholding_mode,</span>
<a name="605"><font size=-1>605     </font></a><span class="default">    </span><span class="keyword">int </span><span class="default">img_int_thr, </span><span class="keyword">int </span><span class="default">area_thr, </span><span class="keyword">float </span><span class="default">ration_thr,</span>
<a name="606"><font size=-1>606     </font></a><span class="default">    </span><span class="keyword">int </span><span class="default">min_order_u, </span><span class="keyword">int </span><span class="default">max_order_u,</span>
<a name="607"><font size=-1>607     </font></a><span class="default">    </span><span class="keyword">int </span><span class="default">min_order_v, </span><span class="keyword">int </span><span class="default">max_order_v,</span>
<a name="608"><font size=-1>608     </font></a><span class="default">    </span><span class="keyword">int </span><span class="default">edge_exclusion) {</span>
<a name="609"><font size=-1>609     </font></a><span class="default"></span>
<a name="610"><font size=-1>610     </font></a><span class="default">    cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_SILENT);</span>
<a name="611"><font size=-1>611     </font></a><span class="default"></span>
<a name="612"><font size=-1>612     </font></a><span class="default">    </span><span class="comment">/** 1 获得用户默认的参数*/</span>
<a name="613"><font size=-1>613     </font></a><span class="comment">    </span><span class="keyword">double </span><span class="default">grid_period = configuration[</span><span class="string">&quot;grid_period&quot;</span><span class="default">];</span>
<a name="614"><font size=-1>614     </font></a><span class="default">    </span><span class="keyword">double </span><span class="default">dist_mask_to_detector = configuration[</span><span class="string">&quot;dist_mask_to_detector&quot;</span><span class="default">];</span>
<a name="615"><font size=-1>615     </font></a><span class="default">    </span><span class="keyword">double </span><span class="default">min_fingre_number = configuration[</span><span class="string">&quot;lowest_fringe_order&quot;</span><span class="default">];</span>
<a name="616"><font size=-1>616     </font></a><span class="default">    </span><span class="keyword">double </span><span class="default">centroid_power = configuration[</span><span class="string">&quot;centroid_power&quot;</span><span class="default">];</span>
<a name="617"><font size=-1>617     </font></a><span class="default">    </span><span class="keyword">double </span><span class="default">detector_pixel_size = configuration[</span><span class="string">&quot;detector_pixel_size&quot;</span><span class="default">];</span>
<a name="618"><font size=-1>618     </font></a><span class="default">    </span><span class="keyword">double </span><span class="default">wavelength = configuration[</span><span class="string">&quot;wavelength&quot;</span><span class="default">];</span>
<a name="619"><font size=-1>619     </font></a><span class="default"></span>
<a name="620"><font size=-1>620     </font></a><span class="default">    </span><span class="comment">/** 2 分析Hartmann 图像*/</span>
<a name="621"><font size=-1>621     </font></a><span class="comment">    </span><span class="default">analyzeHartmanngram(hartmanngram, dist_mask_to_detector, detector_pixel_size, grid_period, HIOlAB_CXX_14::ThresholdMode::OTSU,</span>
<a name="622"><font size=-1>622     </font></a><span class="default">        img_int_thr, </span><span class="number">31</span><span class="default">, area_thr, min_fingre_number, starting_pixel, ration_thr, centroid_power,</span>
<a name="623"><font size=-1>623     </font></a><span class="default">        min_order_u, max_order_u, min_order_v, max_order_v, edge_exclusion, </span><span class="keyword">true</span><span class="default">);</span>
<a name="624"><font size=-1>624     </font></a><span class="default">}</span>
<a name="625"><font size=-1>625     </font></a><span class="default"></span>
<a name="626"><font size=-1>626     </font></a><span class="default"></span>
<a name="627"><font size=-1>627     </font></a><span class="default"></span><span class="keyword">void </span><span class="default">WaveFrontSensor::TestFunction() {}</span>
<a name="628"><font size=-1>628     </font></a><span class="default"></span>
<a name="629"><font size=-1>629     </font></a><span class="default"></span>
<a name="630"><font size=-1>630     </font></a><span class="default"></span>
<a name="631"><font size=-1>631     </font></a><span class="default"></span>
<a name="632"><font size=-1>632     </font></a><span class="default"></span><span class="keyword">void </span><span class="default">WaveFrontSensor::free() {</span>
<a name="633"><font size=-1>633     </font></a><span class="default"></span>
<a name="634"><font size=-1>634     </font></a><span class="default"></span>
<a name="635"><font size=-1>635     </font></a><span class="default">    </span><span class="keyword">if </span><span class="default">(grid_layout_ != nullptr) {</span>
<a name="636"><font size=-1>636     </font></a><span class="default"></span>
<a name="637"><font size=-1>637     </font></a><span class="default">        </span><span class="keyword">delete </span><span class="default">grid_layout_;</span>
<a name="638"><font size=-1>638     </font></a><span class="default">    }</span>
<a name="639"><font size=-1>639     </font></a><span class="default"></span>
<a name="640"><font size=-1>640     </font></a><span class="default">    </span><span class="keyword">if </span><span class="default">(infoText != nullptr) {</span>
<a name="641"><font size=-1>641     </font></a><span class="default"></span>
<a name="642"><font size=-1>642     </font></a><span class="default">        </span><span class="keyword">delete </span><span class="default">infoText;</span>
<a name="643"><font size=-1>643     </font></a><span class="default">    }</span>
<a name="644"><font size=-1>644     </font></a><span class="default"></span>
<a name="645"><font size=-1>645     </font></a><span class="default">    </span><span class="keyword">if </span><span class="default">(dialog != nullptr) {</span>
<a name="646"><font size=-1>646     </font></a><span class="default"></span>
<a name="647"><font size=-1>647     </font></a><span class="default">        </span><span class="keyword">delete </span><span class="default">dialog;</span>
<a name="648"><font size=-1>648     </font></a><span class="default">    }</span>
<a name="649"><font size=-1>649     </font></a><span class="default"></span>
<a name="650"><font size=-1>650     </font></a><span class="default"></span>
<a name="651"><font size=-1>651     </font></a><span class="default">    </span><span class="keyword">if</span><span class="default">(graphio_scene!=nullptr){</span>
<a name="652"><font size=-1>652     </font></a><span class="default">        </span>
<a name="653"><font size=-1>653     </font></a><span class="default">        </span><span class="keyword">delete </span><span class="default">graphio_scene;</span>
<a name="654"><font size=-1>654     </font></a><span class="default">    }</span>
<a name="655"><font size=-1>655     </font></a><span class="default"></span>
<a name="656"><font size=-1>656     </font></a><span class="default">    </span><span class="keyword">if </span><span class="default">(graphic_view != nullptr) {</span>
<a name="657"><font size=-1>657     </font></a><span class="default"></span>
<a name="658"><font size=-1>658     </font></a><span class="default">        </span><span class="keyword">delete </span><span class="default">graphic_view;</span>
<a name="659"><font size=-1>659     </font></a><span class="default">    }</span>
<a name="660"><font size=-1>660     </font></a><span class="default"></span>
<a name="661"><font size=-1>661     </font></a><span class="default">}</span>
<a name="662"><font size=-1>662     </font></a><span class="default"></span>
</pre></body></html>
